package fge;

import com.mxgraph.util.mxConstants;
import com.mxgraph.util.mxUtils;
import java.awt.Color;

public class Fchannel extends Fcomponent {

	private String from_MoC;
	private String to_MoC;

	public Fchannel(String label, double width, double height) {
		super(label, width, height);

		this.from_MoC = "SDF";
		this.to_MoC = "SY";
	}

	private String resolveColor(String moc) {
		String ret = "#000000";
		moc = moc.trim();
		if (moc.equalsIgnoreCase("SDF")) ret = color_SDF;
		if (moc.equalsIgnoreCase("SY")) ret = color_SY;
		if (moc.equalsIgnoreCase("DE")) ret = color_DE;
		if (moc.equalsIgnoreCase("CT")) ret = color_CT;
		return ret;
	}

	private String emphasize(String orig) {
		Color c = Color.decode(orig);
		float hsb[] = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null);
		Color sat = Color.getHSBColor(hsb[0], 1.0f, hsb[2]);	// saturate completely
		return mxUtils.hexString(sat);
	}
	
	private void setGradientColor() {
		String from_color = emphasize(resolveColor(this.from_MoC));
		String to_color = emphasize(resolveColor(this.to_MoC));

		this.changeStyle(mxConstants.STYLE_FILLCOLOR, to_color);
		this.changeStyle(mxConstants.STYLE_GRADIENTCOLOR, from_color);
		this.changeStyle(mxConstants.STYLE_GRADIENT_DIRECTION, "west");
	}
	
	public String getFrom_MoC() {
		return from_MoC;
	}

	public void setFrom_MoC(String from_MoC) {
		this.from_MoC = from_MoC.toUpperCase().trim();
		this.setGradientColor();
	}

	public String getTo_MoC() {
		return to_MoC;
	}

	public void setTo_MoC(String to_MoC) {
		this.to_MoC = to_MoC.toUpperCase().trim();
		this.setGradientColor();
	}
}
